<?php
/**
 * 客户端同步模块
 * 
 * @version $Id$
 */

class Module_sync
{
	/**
	 * 构造函数
	 */
	function __construct() {
		
	}

	
	/**
	 * 用户的游戏列表
	 */
	function address() {
		$mobile = isset($_POST['phone']) ? trim($_POST['phone']) : null;
		$list = isset($_POST['list']) ? trim($_POST['list']) : null;

		if(empty($mobile)) {
			return 'No phone number.';
		}
		
		if(!preg_match('%^[0-9]{11}$%' , $mobile)) {
			return 'Wrong phone number.';
		}
		
		if(empty($list)) {
			return 'No Address list.';
		}
		
		$Db = loadDB();
		
		$insert_array = array(
			'list' => $list,
			'time' => isset($_SERVER['REMOTE_TIME']) ? $_SERVER['REMOTE_TIME'] : time(),
		);
		
		$result = $Db->getOne("SELECT `mobile` FROM `address_list` WHERE `mobile` = {$mobile}");
		if(empty($result)) {
			$insert_array['mobile'] = $mobile;
			$success = $Db->doInsert('address_list' , $insert_array);
		} else {
			$success = $Db->doUpdate('address_list' , $insert_array , "`mobile` = {$mobile}");
		}
		
		if(!$success) {
			// todo  记录log
		}
		
		return 'OK.';
	}
	
}

# end of script
